<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.db.conn" %>
<%@ page import="com.db.Pagination" %>
<%@ page import="java.sql.*" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>
    <style>
        .ms-panel {
            background: #fff;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.12);
            margin-bottom: 24px;
        }
        
        .ms-panel-header {
            padding: 16px 20px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .ms-panel-header h6 {
            margin: 0;
            font-size: 16px;
            font-weight: 500;
            color: #333;
        }
        
        .ms-panel-body {
            padding: 20px;
        }
        
        .search-form {
            background: #f8f9fa;
            padding: 16px;
            border-radius: 4px;
            margin-bottom: 20px;
            text-align: center;
        }
        
        .search-form form {
            display: inline-block;
        }
        
        .search-form strong {
            color: #495057;
            font-weight: 500;
            margin-right: 8px;
        }
        
        .search-form select,
        .search-form input[type="text"] {
            padding: 6px 12px;
            border: 1px solid #ced4da;
            border-radius: 4px;
            font-size: 14px;
            transition: all 0.3s ease;
            width: 150px;
            margin-right: 16px;
        }
        
        .search-form select:focus,
        .search-form input[type="text"]:focus {
            border-color: #80bdff;
            outline: none;
            box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
        }
        
        .search-form input[type="submit"] {
            background: #007bff;
            color: #fff;
            border: none;
            padding: 6px 16px;
            border-radius: 4px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .search-form input[type="submit"]:hover {
            background: #0056b3;
        }
        
        .table-container {
            overflow-x: auto;
            margin: 0 -20px;
            padding: 0 20px;
        }
        
        .data-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        
        .data-table th {
            background: #f8f9fa;
            color: #495057;
            font-weight: 500;
            padding: 12px;
            text-align: center;
            border-bottom: 2px solid #dee2e6;
            font-size: 14px;
        }
        
        .data-table td {
            padding: 12px;
            border-bottom: 1px solid #dee2e6;
            color: #212529;
            font-size: 14px;
            vertical-align: middle;
            text-align: center;
        }
        
        .data-table tr:hover {
            background: #f8f9fa;
        }
        
        .book-cover {
            width: 80px;
            height: 80px;
            object-fit: cover;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        
        .action-links {
            display: flex;
            gap: 8px;
            justify-content: center;
            flex-wrap: wrap;
        }
        
        .action-link {
            color: #007bff;
            text-decoration: none;
            font-size: 13px;
            padding: 4px 8px;
            border-radius: 4px;
            transition: all 0.3s ease;
            background: #f8f9fa;
            border: 1px solid #e9ecef;
        }
        
        .action-link:hover {
            background: #e9ecef;
            color: #0056b3;
        }
        
        .action-link.delete {
            color: #dc3545;
            border-color: #f8d7da;
        }
        
        .action-link.delete:hover {
            background: #f8d7da;
            color: #c82333;
        }
        
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-top: 24px;
            padding: 16px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        
        .pagination a {
            padding: 8px 16px;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            color: #495057;
            text-decoration: none;
            transition: all 0.3s ease;
            font-size: 14px;
            min-width: 40px;
            text-align: center;
            background: #fff;
        }
        
        .pagination a:hover {
            background: #f8f9fa;
            border-color: #dee2e6;
            color: #212529;
            transform: translateY(-1px);
        }
        
        .pagination .active {
            background: #007bff;
            color: #fff;
            border-color: #007bff;
        }
        
        .pagination .active:hover {
            background: #0056b3;
            color: #fff;
            border-color: #0056b3;
            transform: none;
        }
        
        .pagination .disabled {
            color: #adb5bd;
            pointer-events: none;
            background: #f8f9fa;
            border-color: #e9ecef;
        }
    </style>
</head>

<body class="ms-body ms-aside-left-open ms-primary-theme ms-has-quickbar">
    <div class="ms-content-wrapper">
        <div class="row">
            <div class="col-md-12">
                <div class="ms-panel">
                    <div class="ms-panel-header">
                        <h6>管理小说信息</h6>
                    </div>
                    <div class="ms-panel-body">
                        <div class="search-form">
                            <form action="<%=path %>/admin/books/books_Manage.jsp" method="post">
                                <strong>小说类别:</strong>
                                <select name="se_caid" id="caidid">
                                    <option value="">全部</option>
                                    <%
                                        conn cncaid = new conn();
                                        ResultSet rscaid = cncaid.query("select  * from category ");
                                        while (rscaid.next()) {
                                    %>
                                    <option value="<%= rscaid.getString("caid") %>"><%=rscaid.getString("caname")%></option>
                                    <%} %>
                                </select>
                                <strong>小说名称:</strong>
                                <input name="txt_bname" type="text" id="txt_bname"/>
                                <input name="search" type="submit" value='查询'/>
                            </form>
                        </div>

                        <div class="table-container">
                            <table class="data-table">
                                <thead>
                                    <tr>
                                        <th>小说类别</th>
                                        <th>小说名称</th>
                                        <th>小说封面</th>
                                        <th>作者</th>
                                        <th>总字数(万)</th>
                                        <th>价格</th>
                                        <th>点击量</th>
                                        <th>最后更新时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <%
                                        int pageSize = 10;
                                        int pageNow = 1;
                                        int rowCount = 0;
                                        int pageCount = 0;
                                        
                                        String s_pageNow = request.getParameter("pageNum");
                                        if (s_pageNow != null) {
                                            pageNow = Integer.parseInt(s_pageNow);
                                        }

                                        String where = "  1=1 ";

                                        if (request.getParameter("se_caid") != null && request.getParameter("se_caid") != "") {
                                            where += " and a.caid=" + request.getParameter("se_caid");
                                        }

                                        if (request.getParameter("txt_bname") != null) {
                                            where += " and bname like '%" + request.getParameter("txt_bname") + "%' ";
                                        }

                                        conn cn = new conn();

                                        ResultSet rs = cn.query("select count(*) from books a where " + where);
                                        if (rs.next()) {
                                            rowCount = rs.getInt(1);
                                        }

                                        if (rowCount % pageSize == 0) {
                                            pageCount = rowCount / pageSize;
                                        } else {
                                            pageCount = rowCount / pageSize + 1;
                                        }

                                        rs = cn.query("select  a.*,b.caname from books a  left join category b on a.caid=b.caid " +
                                                " where " + where + " order by bid desc limit " + pageSize * (pageNow - 1) + ", " + pageSize);

                                        while (rs.next()) {
                                    %>
                                    <tr>
                                        <td><%=rs.getString("caname") %></td>
                                        <td><%=rs.getString("bname") %></td>
                                        <td><img class="book-cover" alt="小说封面" src="<%=path %>/<%=rs.getString("bpic") %>"/></td>
                                        <td><%=rs.getString("author") %></td>
                                        <td><%=rs.getString("words") %></td>
                                        <td><%=rs.getString("price") %></td>
                                        <td><%=rs.getString("btotal") %></td>
                                        <td><%=rs.getString("btime") %></td>
                                        <td>
                                            <div class="action-links">
                                                <a href="<%=path %>/admin/books/books_Detail.jsp?id=<%=rs.getString("bid") %>" class="action-link">详细</a>
                                                <a href="<%=path %>/admin/books/books_Edit.jsp?id=<%=rs.getString("bid") %>" class="action-link">编辑</a>
                                                <a href="<%=path %>/books_Delete?id=<%=rs.getString("bid") %>" class="action-link delete">删除</a>
                                                <a href="<%=path %>/admin/bmore/bmore_Add.jsp?id=<%=rs.getString("bid") %>" class="action-link">添加章节</a>
                                            </div>
                                        </td>
                                    </tr>
                                    <%} %>
                                </tbody>
                            </table>
                        </div>

                        <div class="pagination">
                            <%= Pagination.getPagination(pageNow, pageCount, rowCount, request.getRequestURI()) %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>







